package com.zyh.question.controller;

import com.zyh.common.annotation.Log;
import com.zyh.common.core.controller.BaseController;
import com.zyh.common.core.domain.AjaxResult;
import com.zyh.common.core.page.TableDataInfo;
import com.zyh.common.enums.BusinessType;
import com.zyh.common.utils.poi.ExcelUtil;
import com.zyh.question.domain.ExamQuestion;
import com.zyh.question.service.IExamQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 选项表Controller
 *
 * @author zyh
 * @date 2025-02-20
 */
@RestController
@RequestMapping("/question/question")
public class ExamQuestionController extends BaseController {
    @Autowired
    private IExamQuestionService examQuestionService;

    /**
     * 查询选项表列表
     */
    //@PreAuthorize("@ss.hasPermi('question:question:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExamQuestion examQuestion) {
        startPage();
        List<ExamQuestion> list = examQuestionService.selectExamQuestionList(examQuestion);
        logger.info("出参->{}", list);
        return getDataTable(list);
    }

    /**
     * 导出选项表列表
     */
    //@PreAuthorize("@ss.hasPermi('question:question:export')")
    @Log(title = "选项管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamQuestion examQuestion) {
        List<ExamQuestion> list = examQuestionService.selectExamQuestionList(examQuestion);
        ExcelUtil<ExamQuestion> util = new ExcelUtil<ExamQuestion>(ExamQuestion.class);
        util.exportExcel(response, list, "选项表数据");
    }

    /**
     * 获取选项表详细信息
     */
    //@PreAuthorize("@ss.hasPermi('question:question:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(examQuestionService.selectExamQuestionById(id));
    }

    /**
     * 新增选项表
     */
    //@PreAuthorize("@ss.hasPermi('question:question:add')")
    @Log(title = "选项管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamQuestion examQuestion) {
        logger.info("ExamQuestionController-->add入参->{}", examQuestion);
        return toAjax(examQuestionService.insertExamQuestion(examQuestion));
    }

    /**
     * 修改选项表
     */
    //@PreAuthorize("@ss.hasPermi('question:question:edit')")
    @Log(title = "选项管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamQuestion examQuestion) {
        logger.info("入参->{}", examQuestion);
        return toAjax(examQuestionService.updateExamQuestion(examQuestion));
    }

    /**
     * 删除选项表
     */
    //@PreAuthorize("@ss.hasPermi('question:question:remove')")
    @Log(title = "选项管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(examQuestionService.deleteExamQuestionByIds(ids));
    }
}
